const http = require('http');

http.createServer(function (request, response) {

    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain

    console.log(request.headers)

    var header = {
        'Content-Type': 'text/plain;charset=utf-8',
        "Access-Control-Allow-Origin": request.headers.origin ? request.headers.origin : '', //解决跨域
        "Access-Control-Allow-Methods": 'PUT, GET, POST, DELETE, OPTIONS', //允许方法
        'Access-Control-Allow-Headers': "x-csrf-token, x-requested-with, Origin, X-Requested-With, Content-Type, Accept, Authorization",
        "Access-Control-Allow-Credentials": true //允许发送Cookie
    }

    header['Authorization'] = 'token09dsds12';
    response.writeHead(200, header);

    // 发送响应数据 "Hello World"
    response.end('http返回数据');
}).listen(8890);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8890/');